<?php
$pacote = "classes/componentes";
$pathToThis = pathinfo(__FILE__);
$root = substr($pathToThis['dirname'], 0, strlen($pathToThis['dirname']) - strlen($pacote) - 1);

require_once $root."/classes/componentes/InputText.class.php";
require_once $root."/classes/conversores/ConversorDataHumanaSql.class.php";

class InputTextData extends InputText {

    function InputTextData($label, $required = false, $valorInicial = null, $mLength = 10, $classStyle="InputText") {
    	$this->setLabel($label);
    	$this->setObrigatorio($required);
    	$this->setValor($valorInicial);
    	$this->setMaxLength($mLength);
    	$this->setConversor(new ConversorDataHumanaSql());
    	$this->setClassStyle($classStyle);
    }
    
	public function getValorConvertido() {
		if (!$this->getHabilitado())
			return $this->getValor();
		$valorSubmetidoConv = $this->getValorSubmetido();
		$valorConv = $this->getValor();
		
		if (!is_null($this->getConversor())) {
			if (!is_null($this->getValorSubmetido()) && $this->getValorSubmetido() != "")
				$valorSubmetidoConv = $this->getConversor()->converte($this->getValorSubmetido());
			else if (!is_null($this->getValor()) && $this->getValor() != "")
				$valorConv = $this->getConversor()->converte($this->valor);
		}
		if (!is_null($this->getValorSubmetido()) && ($this->getValorSubmetido() != "" )) // || is_int($this->getValorSubmetido())
			return $valorSubmetidoConv;
		else
		if (!is_null($this->getValor()) && ($this->getValor() != "" || is_int($this->getValor())) && ($this->getValorSubmetido() != "" )) //|| is_int($this->getValorSubmetido())
			return $valorConv;
		else
			return null;
	}
}
?>